//
//  PictureViewController.m
//  Funny
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 King. All rights reserved.
//

#import "PictureViewController.h"
#import "PictureCollectionViewCell.h"
@interface PictureViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property(nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
@end

@implementation PictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createCollectionView];
}


- (void)createCollectionView
{                                                                                                   
    self.flowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    [self.flowLayout setItemSize:CGSizeMake(self.view.bounds.size.width-1,  self.view.bounds.size.height-260)];
    self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 1, 0, 0);
    self.flowLayout.minimumInteritemSpacing = 1;
    self.flowLayout.minimumLineSpacing = 1;
    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:_flowLayout];
    [self.view addSubview:_collectionView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.collectionView.showsHorizontalScrollIndicator = false;
    self.collectionView.backgroundColor = [UIColor blackColor];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = YES;
    
    [self.collectionView registerClass:[PictureCollectionViewCell class] forCellWithReuseIdentifier:@"photo"];
   
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.imageListArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PictureCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photo" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor blackColor];
    cell.nameLable.text = self.productName;
    [cell.bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://cdn.yaochufa.com/%@", [[self.imageListArray objectAtIndex:indexPath.item] objectForKey:@"url"]]]];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
